﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DNADataHiding.Model;

namespace DNADataHiding.Service
{
    public class DNASequenceService : IDNASequenceService
    {
        private readonly IDictionary<string, string> _sequences;
        
        public DNASequenceService()
        {
            _sequences = new Dictionary<string, string>();
           // _sequences.Add("Sequence faked Test ", "ACGGAATTGCTTCAG"); 
            GenerateRandomSequences();
        }

        private void GenerateRandomSequences()
        {
            Random r = new Random();

            StringBuilder sequence = new StringBuilder();

            for (int i = 0; i < 15; i++)
            {
                sequence.Clear();

                for (int j = 0; j < 2500; j++)
                {
                    switch (r.Next(1, 5))
                    {
                        case 1:
                            {
                                sequence.Append("A");
                                break;
                            }
                        case 2:
                            {
                                sequence.Append("C");
                                break;
                            }
                        case 3:
                            {
                                sequence.Append("G");
                                break;
                            }
                        case 4:
                            {
                                sequence.Append("T");
                                break;
                            }
                    }
                }

             _sequences.Add("Random Sequence " + i.ToString(), sequence.ToString());
               
            }
        }

        public IList<string> GetAllSequencesNames()
        {
            return _sequences.Keys.ToList();
        }

        public IDictionary<string, string> GetAllSequences()
        {
            return _sequences;
        }

        public Model.DNASequence GetSequenceByName(string sequenceName)
        {
            string sequence;

            if (_sequences.TryGetValue(sequenceName, out sequence))
            {
                return new DNASequence(sequence);
            }

            return null;
        }
    }
}
